import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:mi_mang_flutter/utils/locale_util.dart';

/// 相机选择弹出框
class PickImageDialog extends StatelessWidget {
  PickImageDialog({
    Key? key,
  }) : super(key: key);

  /// 相机选择弹出
  /// [return int] 1: 拍照, 0: 从相册中选择
  static Future<int?> show(BuildContext context) {
    return showCupertinoModalPopup(
      context: context,
      builder: (BuildContext context) {
        return PickImageDialog();
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    /// 按钮高度
    const double _buttonHeight = 60.0;

    ///单个选项高度
    const double _spacing = 60.0;

    return Container(
      margin: const EdgeInsets.symmetric(
        horizontal: 15.0,
        vertical: 15.0,
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          Container(
            height: _spacing,
            child: TextButton(
              style: ButtonStyle(
                shape: WidgetStateProperty.all(RoundedRectangleBorder(
                  borderRadius: BorderRadius.vertical(
                    top: Radius.circular(12.0),
                  ),
                )),
                foregroundColor: WidgetStateProperty.all(Colors.blue),
                backgroundColor:
                    WidgetStateProperty.all(Theme.of(context).canvasColor),
                overlayColor:
                    WidgetStateProperty.all(Theme.of(context).splashColor),
              ),
              child: Text(i18n(context).takePhoto),
              onPressed: () {
                Navigator.pop(context, 1);
              },
            ),
          ),
          Divider(
            indent: 0.0,
            thickness: 0.5,
          ),
          Container(
            height: _spacing,
            child: TextButton(
              style: ButtonStyle(
                shape: WidgetStateProperty.all(RoundedRectangleBorder(
                  borderRadius: BorderRadius.vertical(
                    bottom: Radius.circular(12.0),
                  ),
                )),
                foregroundColor: WidgetStateProperty.all(Colors.blue),
                backgroundColor:
                    WidgetStateProperty.all(Theme.of(context).canvasColor),
                overlayColor:
                    WidgetStateProperty.all(Theme.of(context).splashColor),
              ),
              child: Text(i18n(context).chooseFromAlbum),
              onPressed: () {
                Navigator.pop(context, 0);
              },
            ),
          ),
          SizedBox(height: 10.0),
          Container(
            height: _buttonHeight,
            child: TextButton(
              style: ButtonStyle(
                shape: WidgetStateProperty.all(
                  RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(
                      Radius.circular(12.0),
                    ),
                  ),
                ),
                backgroundColor:
                    WidgetStateProperty.all(Theme.of(context).canvasColor),
                overlayColor:
                    WidgetStateProperty.all(Theme.of(context).splashColor),
              ),
              child: Text(i18n(context).cancel),
              onPressed: () {
                Navigator.pop(context, null);
              },
            ),
          ),
        ],
      ),
    );
  }
}
